package mo.leetcode_top;

public class L121 {

    public int maxProfit(int[] prices) {
        int res = 0;
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < prices.length; i++) {
            if (prices[i] < min) {
                min = prices[i];
                continue;
            }
            res = Math.max(res, prices[i] - min);
        }
        return res;
    }

    public static void main(String[] args) {
        L121 test = new L121();
        System.out.println(test.maxProfit(new int[]{7,6,4,3,1}));
    }

}
